package com.b.sts.controller;


import com.b.sts.annotation.PassAuth;
import com.b.sts.service.CommService;
import com.b.sts.util.ResultUtil;
import com.b.sts.vo.ResultVO;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/comm")
public class CommController {
    @Resource
    CommService service;

    @PostMapping("/upload")
    public ResultVO<String> upload(MultipartFile file) {
        String data = service.upload(file);
        return ResultUtil.success(data);
    }
    @PostMapping("/form")
    public ResultVO<String> uploadForm(MultipartFile file) {
        String data = service.uploadForm(file);
        return ResultUtil.success(data);
    }

    @PassAuth
    @GetMapping("/{url}")
    public ResponseEntity<FileSystemResource> get(@PathVariable String url) {
        return service.get(url);
    }

}
